import DateUtil from "@/plugins/date";
import axios from "../axios";
import apiList from "./api-list";
import type { OrderProductDTO, CreateOrderVO, OrderDetailDTO, OrderProductCheckDetailDTO, OrderProductCheckVO, OrderProductRepairDTO, OrderProductRepairVO, OrderViewDTO, QueryOrderVO, OrderDTO, OrderStatisticByDateDTO, CustomerSearchDTO } from "./types";

class AfterSaleOrderController {
  export(value: QueryOrderVO, selectIds: string[]) {
    return axios.post<string>(apiList.export, { query: value, selectedIds: selectIds });
  }
  getOrderNumber() {
    return axios.get<string>(apiList.getOrderNumber, {})
  }
  page(query: QueryOrderVO) {
    return axios.post<OrderViewDTO[]>(apiList.page, query);
  }
  detail(orderId: string) {
    return axios.get<OrderDetailDTO>(apiList.detail, { orderId });
  }
  delete(orderId: string) {
    return axios.get(apiList.delete, { orderId });
  }
  invalid(orderId: string) {
    return axios.get(apiList.invalid, { orderId });
  }
  deleteProduct(orderId: string, productSn: string) {
    return axios.get(apiList.deleteProduct, { orderId, productSn });
  }
  getBaseInfo(orderId: string) {
    return axios.get<OrderDTO>(apiList.baseInfo, { orderId });
  }
  create(data: CreateOrderVO) {
    return axios.post<string>(apiList.create, data);
  }
  update(data: CreateOrderVO) {
    return axios.post<string>(apiList.update, data);
  }
  getProductDetail(orderId: string, productSn: string) {
    return axios.get<OrderProductDTO>(apiList.getProductDetail, { orderId, productSn });
  }
  getCheckDetail(orderId: string, productSn: string) {
    return axios.get<OrderProductCheckDetailDTO>(apiList.getCheckDetail, { orderId, productSn })
  }
  createCheckDetail(data: OrderProductCheckVO) {
    return axios.post(apiList.createCheckDetail, data);
  }
  updateCheckDetail(data: OrderProductCheckVO) {
    return axios.post(apiList.updateCheckDetail, data);
  }
  getRepairDetail(orderId: string, productSn: string) {
    return axios.get<OrderProductRepairDTO>(apiList.getRepairDetail, { orderId, productSn })
  }
  createRepairDetail(data: OrderProductRepairVO) {
    return axios.post(apiList.createRepairDetail, data)
  }
  updateRepairDetail(data: OrderProductRepairVO) {
    return axios.post(apiList.updateRepairDetail, data)
  }
  getRepairCount(productSn: string) {
    return axios.get<number>(apiList.getRepairCount, { productSn })
  }
  importData(fileId: string) {
    return axios.get(apiList.importData, { fileId });
  }
  generateReport(orderId: string) {
    return axios.get<string>(apiList.generateReport, { orderId });
  }
  dateOrderStatistic(startDate: string, endDate: string) {
    return axios.post<OrderStatisticByDateDTO[]>(apiList.dateOrderStatistic, { startDate: DateUtil.formatToTime(startDate), endDate: DateUtil.formatToTime(endDate) })
  }
  countByState() {
    return axios.get<{ orderStatusName: string, count: number }[]>(apiList.countByState, {});
  }
  countByProductRepairState() {
    return axios.get<{ repairState: string, count: number }[]>(apiList.countByProductRepairState, {});
  }
  oneKeyPrice(orderId: string, quoteDate: string) {
    return axios.post(apiList.oneKeyPrice, { orderId, quoteDate })
  }
  customerSearch(searchKey: string, captcha: string) {
    return axios.get<CustomerSearchDTO[]>(apiList.customerSearch, { searchKey, captcha });
  }
}

export default AfterSaleOrderController;
